
component  output="false" extends="AbsFactory"
{

	public CommentFactory function init(){
		
		return this;
	}
	
	public it.millemultimedia.easyBlog.validator.CommentValidator function getValidator(){
		
		return new it.millemultimedia.easyBlog.validator.CommentValidator();
	}
	
	public it.millemultimedia.easyBlog.model.Comment function createInstance(){
		
		return new it.millemultimedia.easyBlog.model.Comment();
	}
	
	public it.millemultimedia.easyBlog.model.Comment function get( required Query Comments ){
		
		var list = createObject( 'java','java.util.ArrayList' ).init();
		var obj = createInstance() ;
		var end = 0 ;
		var i = 1 ;
		var c = 1 ;
		
		obj = build( arguments.Comments, i );
		
		return obj;
	}
	
	public it.millemultimedia.easyBlog.model.Comment[] function list( required Query Comments, Numeric start=0, Numeric count=0 ){
		
		var list = createObject( 'java','java.util.ArrayList' ).init();
		var obj = "";
		var end = 0 ;
		var i = 1 ;
		
		if( arguments.start eq 0 and arguments.count eq 0 ){
		
			arguments.start = 1;
			end = arguments.Comments.recordcount;
		
		}else{
		
			if( (arguments.start + arguments.count - 1) GTE arguments.Comments.recordcount ){
			
				end =  arguments.Comments.recordcount ;
				
			}else{
			
				end= arguments.start + arguments.count - 1 ;
	
			}
		
		}
		
		for( i=arguments.start; i<=end; i++ ){
		
			obj = build( arguments.Comments, i ) ;
			
			list.add( obj ) ;
		
		}
		
		return list;
		
	}
	
	private it.millemultimedia.easyBlog.model.Comment function build( required Query Comments, required Numeric index ){
		
		var list = createObject( 'java','java.util.ArrayList' ).init();
		var obj = createInstance();
		var i = arguments.index;
		
		
		if( structKeyExists( arguments.Comments, 'Idcomment' ) ){
		
		obj.setIdcomment(arguments.Comments.Idcomment[i]);

		}
		if( structKeyExists( arguments.Comments, 'Idpost' ) ){
		
		obj.setIdpost(arguments.Comments.Idpost[i]);

		}
		if( structKeyExists( arguments.Comments, 'Status' ) ){
		
		obj.setStatus(arguments.Comments.Status[i]);

		}
		if( structKeyExists( arguments.Comments, 'Postdate' ) ){
		
		obj.setPostdate(arguments.Comments.Postdate[i]);

		}
		if( structKeyExists( arguments.Comments, 'Uuid' ) ){
		
		obj.setUuid(arguments.Comments.Uuid[i]);

		}
		if( structKeyExists( arguments.Comments, 'Name' ) ){
		
		obj.setName(arguments.Comments.Name[i]);

		}
		if( structKeyExists( arguments.Comments, 'Email' ) ){
		
		obj.setEmail(arguments.Comments.Email[i]);

		}
		if( structKeyExists( arguments.Comments, 'Website' ) ){
		
		obj.setWebsite(arguments.Comments.Website[i]);

		}
		if( structKeyExists( arguments.Comments, 'Comment' ) ){
		
		obj.setComment(arguments.Comments.Comment[i]);

		}
		
		return obj;
	}

}
